﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Benday.ListControls.Presentation;
using System.Windows.Markup;
using System.Text;

namespace Benday.ListControls
{
    public partial class RadioButtonList : UserControl
    {
        public RadioButtonList()
        {
            InitializeComponent();
        }

        public ObservableCollection<ISelectableItem> Items
        {
            get
            {
                ObservableCollection<ISelectableItem> viewModel =
                    this.DataContext as ObservableCollection<ISelectableItem>;

                if (viewModel == null)
                {
                    viewModel = new ObservableCollection<ISelectableItem>();

                    this.DataContext = viewModel;
                }

                return viewModel;
            }
        }

       
        public Orientation Orientacion
        {
            set
            {
                m_itemsControl.ItemsPanel = (ItemsPanelTemplate)XamlReader.Load(CreateItemsPanelTemplate(value));
            }
        }

        private string CreateItemsPanelTemplate(Orientation poOrientacion)
        {
            StringBuilder ipTempl = new StringBuilder();
            ipTempl.Append("<ItemsPanelTemplate ");
            ipTempl.Append("xmlns='http://schemas.microsoft.com/client/2007' ");
            ipTempl.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
            ipTempl.Append("xmlns:toolkit='http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit'>");

            // Dynamically construct WrapPanel properties based on OlafRibbonItemBox properties
            ipTempl.Append("<StackPanel ");
            // If MaxHeight or MaxWidth were not set just close WrapPanel element
            if (poOrientacion == Orientation.Vertical)
            {
                ipTempl.Append("Orientation='Vertical' ");
            }
            else
            {
                ipTempl.Append("Orientation='Horizontal' ");
            }

            ipTempl.Append("/>");
            ipTempl.Append("</ItemsPanelTemplate>");

            return ipTempl.ToString();
        }
    }
}
